//
//  NWSingleton.h
//  noworry
//
//  Created by dl on 2017/10/16.
//  Copyright © 2017年 dl. All rights reserved.
//

#import <Foundation/Foundation.h>

#ifndef NWSingleton_h
#define NWSingleton_h

#define NW_SINGLETON_INSTANCE_METHOD_DECLARATION_NAMED(methodName) + (instancetype)methodName;
#define NW_SINGLETON_INSTANCE_METHOD_DECLARATION + (instancetype)sharedInstance;
#define NW_SINGLETON_INSTANCE_METHOD_DECLARATION_NONNULL + (instancetype _Nonnull)sharedInstance;
#define NW_SINGLETON_INSTANCE_METHOD_DECLARATION_NULLABLE + (instancetype _Nullable)sharedInstance;

#define NW_SINGLETON_INSTANCE_METHOD_IMPLEMENTATION_NAMED(methodName) \
+ (instancetype)methodName \
{\
static dispatch_once_t pred = 0; \
__strong static id _sharedObject = nil; \
dispatch_once(&pred, ^{ \
_sharedObject = [[self alloc] init]; \
}); \
return _sharedObject; \
}\

#define NW_SINGLETON_INSTANCE_METHOD_IMPLEMENTATION NW_SINGLETON_INSTANCE_METHOD_IMPLEMENTATION_NAMED(sharedInstance)

#define NW_SINGLETON_INSTANCE_METHOD NW_SINGLETON_INSTANCE_METHOD_IMPLEMENTATION


#endif /* NWSingleton_h */
